package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.UserMapper;
import com.qf.pojo.TUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Author: 杨林涛
 * @Date: 2022/8/29 0029 19:09
 */
@Service
public class UserServiceImpl  implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //条件查询
        LambdaQueryWrapper<TUser> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(TUser::getUsername,username);
        TUser tUser = userMapper.selectOne(lambdaQueryWrapper);
        if (tUser!=null){

            return User.withUsername(username)
                    .password(tUser.getPassword())
                    .roles()
                    .build();
        }

        System.out.println("用户名不存在");
        return null;

    }
}
